// element-plus 组件库自动按需导入配置
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')

const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const webpack = require('webpack')

module.exports = {
  // lintOnSave: false,
  publicPath: '/',
  // 关闭严格语法检测
  productionSourceMap: false,
  // 开发模式反向代理配置，生产模式请使用Nginx部署并配置反向代理
  devServer: {
    disableHostCheck: true,
    port: 1888,
    proxy: {
      '/api/apikey': {
        target: 'https://api.uixsj.cn/hitokoto/get', // 本地多服务
        // target: 'http://ipoot.com', // 本地多服务
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          '^/api/apikey': ''
        }
      },

      '/api': {
        // 本地服务接口地址
        // target: 'http://localhost:8101', // 本地多服务
        // target: 'http://101.201.81.193:8101', // 线上服务
        changeOrigin: true,
        target: process.env.VUE_APP_SERVER_URL, //  本地环境
        ws: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  },
  configureWebpack: {
    // element-plus 组件库自动按需导入插件配置
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      }),
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'windows.jQuery': 'jquery'
      })
    ]
  },
  chainWebpack: (config) => {
    config.plugin('loadshReplace').use(new LodashModuleReplacementPlugin())
  },
  css: {
    loaderOptions: {
      sass: {
        data: ` @import "./src/assets/css/variables.scss";
                @import "./src/assets/css/mixin.scss";`
      },
      scss: {
        prependData: ' @import "~@/variables.scss"; '
      }
    }
  }
}
